

#include "gpio.h"
#include "cpu_io.h"
#include "uart.h"


void uart_init(void)
{
	struct s5pv210_gpio *gpio = (struct s5pv210_gpio *)S5PV10_GPIO_BASE;
	struct s5pv210_uart *uart0 = (struct s5pv210_uart *)S5PV10_UART_BASE;
	unsigned int var;

	var = __REG(&gpio->a0.con);
	var &= ~(0xff);
	var |= 0x22;
	__REG(&gpio->a0.con) = var;

	/*config uart controller*/
	__REG(&uart0->ulcon) = 0x03;	/*8bit, no parity*/
	__REG(&uart0->ucon) = 0x05;	/*Interrupt request or polling mode*/
	__REG(&uart0->ubrdiv) = 35;
	__REG(&uart0->udivslot) = 0x1;
}

void putc(const char c)
{
	struct s5pv210_uart *uart0 = (struct s5pv210_uart *)S5PV10_UART_BASE;

	while(!(__REG(&uart0->utrstat) & (0x1<<2)));

	__REG(&uart0->utxh) = c;
}

void puts(const char *s)
{
	struct s5pv210_uart *uart0 = (struct s5pv210_uart *)S5PV10_UART_BASE;
	char *p = (char *)s;
	
	while(*p)
	{
		if(*p == '\n'){
			putc('\r');
			while(!(__REG(&uart0->utrstat) & (0x1<<2)));
		}
		putc(*p);
		p++;
	}
}

#if 0
void kprintf(const char *fmt, ...)
{
	va_list args;
	unsigned int length;
	static char log_buf[CONSOLEBUF_SIZE];
	
	va_start(args, fmt);
	
	vsnprintf(log_buf, CONSOLEBUF_SIZE + 1, fmt, args);
	
	puts(log_buf);

	va_end(args);
}
#endif

